package com.hydl.power.service.impl;

import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import com.github.pagehelper.PageInfo;
import com.hydl.power.mapper.TempDeviceMapper;
import com.hydl.power.pojo.TempDevice;
import com.hydl.power.pojo.TempDeviceExample;
import com.hydl.power.service.TempDeviceService;

/**
 * @author miss
 * @description 变压器温控设备
 * @date 2023-01-04
 */
@Service
public class TempDeviceServiceImpl implements TempDeviceService {

    @Autowired
    private TempDeviceMapper tempDeviceMapper;

    @Override
    public int insert(TempDevice tempDevice) {
        return tempDeviceMapper.insertSelective(tempDevice);
    }

    @Override
    public int delete(int id) {
        TempDeviceExample example = new TempDeviceExample();
        TempDeviceExample.Criteria criteria = example.createCriteria();
        criteria.andIdEqualTo(id);
        return tempDeviceMapper.deleteByExample(example);
    }

    @Override
    public int update(TempDevice tempDevice) {
        TempDeviceExample example = new TempDeviceExample();
        TempDeviceExample.Criteria criteria = example.createCriteria();
        criteria.andIdEqualTo(tempDevice.getId());
        return tempDeviceMapper.updateByExampleSelective(tempDevice, example);
    }

    @Override
    public TempDevice load(int id) {
        TempDeviceExample example = new TempDeviceExample();
        TempDeviceExample.Criteria criteria = example.createCriteria();
        criteria.andIdEqualTo(id);
        List<TempDevice> tempDeviceList = tempDeviceMapper.selectByExample(example);
        return CollectionUtils.isEmpty(tempDeviceList) ? null : tempDeviceList.get(0);
    }

    @Override
    public PageInfo<TempDevice> pageList(int pageNum, int pageSize, TempDevice tempDevice) {
        TempDeviceExample example = new TempDeviceExample();
        // TempDeviceExample.Criteria criteria = example.createCriteria();
        // criteria.andIdEqualTo(tempDevice.getId());
        List<TempDevice> pageList = tempDeviceMapper.selectPage(pageNum,pageSize);
        return new PageInfo<>(pageList);
    }

    @Override
    public List<TempDevice> query(TempDevice tempDevice) {
        TempDeviceExample example = new TempDeviceExample();
        TempDeviceExample.Criteria criteria = example.createCriteria();
        criteria.andPowerroomIdEqualTo(tempDevice.getPowerroomId());
        return tempDeviceMapper.selectByExample(example);
    }

}